﻿using System;
using System.Collections.Generic;
using Socium.Domain.Collections;
using Socium.Domain.Persons;

namespace Socium.Domain.Tests.Testings {
	[Serializable]
	public class Testing {
		public Testing() : this(DateTime.Now) { }

		public Testing(DateTime date) {
			Date = date;

			Tests = new LinkedList<Test>();
		}

		public DateTime Date { get; private set; }

		public ICollection<Test> Tests { get; private set; }

		readonly ICollection<Answer> _answers = new LinkedList<Answer>();
		public IEnumerable<Answer> Answers {
			get { return _answers; }
		}

		public override string ToString() {
			return Date.ToString();
		}

		public void RemoveAnswers(Person person, object key) {
			FindAnswers(person, key).Iterate(answer => _answers.Remove(answer));
		}

		public void AddAnswer(Answer answer) {
			_answers.Add(answer);
		}

		public IEnumerable<Answer> FindAnswers(Person person, object key) {
			return _answers.Filter(answer => answer.IsMatch(person, key));
		}

		public Answer FindAnswer(Person person, object key) {
			return _answers.Find(answer => answer.IsMatch(person, key), null);
		}
	}
}
